Skip to content

Fix clearTimeout timer leaks in AbortController fetch patterns#36

Merged
groupthinking merged 4 commits intomainfrom
copilot/sub-pr-33-another-one
Feb 27, 2026
Merged

Fix clearTimeout timer leaks in AbortController fetch patterns#36
groupthinking merged 4 commits intomainfrom
copilot/sub-pr-33-another-one

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

clearTimeout was placed after await fetch(...) in both /api/video and /api/transcribe routes, meaning it never ran when the fetch threw (including the intentional AbortError from the signal). This left timers pending in every error/abort path.

Changes

  • apps/web/src/app/api/video/route.ts — Wrapped the 15s backend fetch in try/finally so the timeout is always cleared
  • apps/web/src/app/api/transcribe/route.ts — Same fix for the 8s YouTube backend transcript fetch
// Before
const timeout = setTimeout(() => controller.abort(), 15_000);
const response = await fetch(..., { signal: controller.signal });
clearTimeout(timeout); // never reached on abort/throw

// After
let response: Response;
try {
  response = await fetch(..., { signal: controller.signal });
} finally {
  clearTimeout(timeout); // always runs
}

Also included in this branch (prior commits):

  • transcript_segments now correctly reads result.transcript?.segments?.length for object-shaped transcripts, falling back to result.transcript.length for arrays
  • ENABLE_VERTEX_AI env var now parsed as an explicit boolean ("1"/"true"/"yes") instead of raw truthiness, preventing "0" or "false" from triggering the slow Vertex AI metadata probe

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Contributor

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v0-uvai Error Error Feb 27, 2026 11:09pm

@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-36 February 27, 2026 22:50 Destroyed
@railway-app
Copy link

railway-app bot commented Feb 27, 2026

🚅 Deployed to the EventRelay-pr-36 environment in EventRelay

Service Status Web Updated (UTC)
web ✅ Success (View Logs) Web Feb 27, 2026 at 11:04 pm
supabase ✅ Success (View Logs) Feb 27, 2026 at 11:03 pm
EventRelay ✅ Success (View Logs) Web Feb 27, 2026 at 11:02 pm
eslint-config ✅ Success (View Logs) Web Feb 27, 2026 at 11:02 pm
guides ✅ Success (View Logs) Web Feb 27, 2026 at 11:02 pm

…eouts

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-36 February 27, 2026 22:54 Destroyed
Copilot AI changed the title [WIP] Add frontend-only video analysis pipeline with multi-strategy transcription Fix clearTimeout timer leaks in AbortController fetch patterns Feb 27, 2026
@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-36 February 27, 2026 23:01 Destroyed
@groupthinking groupthinking marked this pull request as ready for review February 27, 2026 23:01
@groupthinking groupthinking self-requested a review as a code owner February 27, 2026 23:01
Copilot AI review requested due to automatic review settings February 27, 2026 23:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes timer leaks in the AbortController fetch patterns in two Next.js API routes. Previously, clearTimeout was called immediately after await fetch(...), meaning if the fetch threw an error (such as an AbortError triggered by the signal itself), the timeout would never be cleared. The fix wraps each fetch in a try/finally block so clearTimeout is guaranteed to run on all code paths. The package-lock.json changes reflect routine dependency tree cleanup (@swc/core, @cfworker/json-schema, and related peer packages removed as optional/unused, and fsevents dev flag update).

Changes:

  • apps/web/src/app/api/video/route.ts: Wrapped the 15-second backend fetch in try/finally to always clear the abort timer.
  • apps/web/src/app/api/transcribe/route.ts: Same try/finally fix for the 8-second backend fetch.
  • package-lock.json: Removes entries for @swc/core, @cfworker/json-schema, and related packages that were optional peer dependencies, and updates the fsevents entry (removal of the "dev": true flag — a common npm install artifact).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
apps/web/src/app/api/video/route.ts Wraps 15s backend fetch in try/finally to guarantee clearTimeout runs on abort/throw
apps/web/src/app/api/transcribe/route.ts Wraps 8s backend fetch in try/finally to guarantee clearTimeout runs on abort/throw
package-lock.json Removes unused optional peer packages (@swc/core, @cfworker/json-schema, etc.) and updates fsevents metadata

Base automatically changed from claude/slack-check-status-update-R47Ph to main February 27, 2026 23:05
Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestions:

  1. Missing dataconnect-generated module causes build failure with "Cannot find module" error and additional TypeScript type errors
  1. Missing index.ts file in embeddings package causes build failure due to entry point mismatch between package.json and TypeScript output

Fix on Vercel

@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-36 February 27, 2026 23:08 Destroyed
@groupthinking groupthinking merged commit 6ecc4c3 into main Feb 27, 2026
13 of 15 checks passed
@groupthinking groupthinking deleted the copilot/sub-pr-33-another-one branch February 27, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants